@using Abp.Collections.Extensions
@using FwProject.Web.Views
@model FwProject.Web.Views.Shared.Components.NavMenu.NavMenuViewModel
@{
    var calculateMenuUrl = new Func<string, string>((url) =>
    {
        if (string.IsNullOrEmpty(url))
        {
            return "javascript:;";//return ApplicationPath;
        }

        if (UrlChecker.IsRooted(url))
        {
            if (url.StartsWith("/"))
                return Url.Content("~" + url);
            return url;
        }
        return ApplicationPath + url;
    });
    int i = 1;
}

@foreach (var menuItem in Model.MainMenu.Items)
{
    <li class="layui-nav-item">
        <a href="javascript:;">
            @*<i class="layui-icon layui-font">@(string.IsNullOrWhiteSpace(menuItem.Icon) ? Html.Raw("&#xe658;") : Html.Raw(menuItem.Icon))</i>*@
            <span> @menuItem.DisplayName.Trim(new char[] { '[', ']' })</span>
        </a>
        @if (!menuItem.Items.IsNullOrEmpty())
        {
            <dl class="layui-nav-child">
                @foreach (var subMenuItem in menuItem.Items)
                {
                    <dd class="@(subMenuItem.Items.Count>0?"laydate-theme-grid":"")">
                        <a href="javascript:;" @(subMenuItem.Items.Count > 0 ? "" : "kit-target") data-options="{@(subMenuItem.Items.Count>0?"":"url:'"+calculateMenuUrl(subMenuItem.Url)+"',")icon:'@(string.IsNullOrWhiteSpace(subMenuItem.Icon)?Html.Raw("&#xe658;"): Html.Raw(subMenuItem.Icon))',title:'@subMenuItem.DisplayName.Trim(new char[] { '[', ']' })',id:'@(i++)'}">
                            @*<i class="layui-icon">@(string.IsNullOrWhiteSpace(subMenuItem.Icon) ? Html.Raw("&#xe658;") : Html.Raw(subMenuItem.Icon))</i>*@<span> @subMenuItem.DisplayName.Trim(new char[] { '[', ']' })</span>@if (subMenuItem.Items.Count > 0)
                            {<i class="layui-nav-mored"></i>}
                        </a>
                        @if (!subMenuItem.Items.IsNullOrEmpty())
                        {
                            foreach (var thirdMenuItem in subMenuItem.Items)
                            {
                                <dl class="layui-nav-child">
                                    <dd data-name="list">
                                        <a href="javascript:;" kit-target data-options="{url:'@calculateMenuUrl(thirdMenuItem.Url)',icon:'@(string.IsNullOrWhiteSpace(thirdMenuItem.Icon)?Html.Raw("&#xe658;"): Html.Raw(thirdMenuItem.Icon))',title:'@thirdMenuItem.DisplayName.Trim(new char[] { '[', ']' })',id:'@(i++)'}">
                                            @*<i class="layui-icon">@(string.IsNullOrWhiteSpace(thirdMenuItem.Icon) ? Html.Raw("&#xe658;") : Html.Raw(thirdMenuItem.Icon))</i>*@
                                            <span> @thirdMenuItem.DisplayName.Trim(new char[] { '[', ']' })</span>
                                        </a>
                                    </dd>
                                </dl>
                            }
                        }
                    </dd>
                }
            </dl>
        }
    </li>
}